package com.mzkj.wanjulaile.mobile.api.modules.account.controller;

import com.mzkj.common.data.StatusCode;
import com.mzkj.wanjulaile.mobile.api.common.controller.BaseController;
import com.mzkj.wanjulaile.mobile.api.common.entity.ResultEntity;
import com.mzkj.wanjulaile.mobile.api.modules.account.entity.VipScheme;
import com.mzkj.wanjulaile.mobile.api.modules.account.service.VipSchemeService;
import com.mzkj.wanjulaile.mobile.api.modules.session.service.SessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Controller
@RequestMapping(value = "auth/vipScheme")
public class VipSchemeAuthController extends BaseController {
    @Autowired
    private VipSchemeService vipSchemeService;

    @Autowired
    private SessionService sessionService;

    /**
     *
     * @param  request accessToken
     * @return
     */
    @RequestMapping("/getVipInfo")
    @ResponseBody
    public ResultEntity<List> getVipInfo(HttpServletRequest request) {
        ResultEntity<List> result = new ResultEntity<>();
        String id=(String)request.getAttribute("accountId");
        try {
            List<VipScheme> vipSchemes = vipSchemeService.findVipSchemes(new VipScheme(), id);
            result.setStatusCode(StatusCode.SC0.getValue());
            result.setMsg(StatusCode.SC0.getDesc());
            result.setData(vipSchemes);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            result.setStatusCode(StatusCode.SC4002.getValue());
            result.setMsg(StatusCode.SC4002.getDesc());
        }
        return result;
    }

    @RequestMapping("/getVipDetail")
    @ResponseBody
    public ResultEntity<VipScheme> getVipDetail(String id,HttpServletRequest request ) {
        String accountId=(String)request.getAttribute("accountId");
        ResultEntity<VipScheme> result = new ResultEntity<VipScheme>();
        try {
            VipScheme vipScheme = vipSchemeService.getVipDetail(id, accountId);
            result.setStatusCode(StatusCode.SC0.getValue());
            result.setMsg(StatusCode.SC0.getDesc());
            result.setData(vipScheme);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            result.setStatusCode(StatusCode.SC4002.getValue());
            result.setMsg(StatusCode.SC4002.getDesc());
        }
        return result;
    }



}